<?php

require_once('Ingenii/Core.php');

class Ingenii_Loader extends Ingenii_Core {
	
	static function autoload($classname) {
		if(substr($classname, 0, 5) == 'Base_') {
			$classname_path = BASEPATH . "/models/classes/base/$classname.php";
		} elseif(substr($classname, 0, 7) == 'Module_') {
	    	$classname_parts = explode('_', $classname);
	    	array_shift($classname_parts);	    	
	    	$classname_path = BASEPATH . "/modules/".implode("/",$classname_parts).".php";
		} else {
			$classname_path = BASEPATH . "/models/classes/$classname.php";
		}
		
		if(!file_exists($classname_path)) {
			$classname_path = str_replace('_', '/', $classname);
			$classname_path = BASEPATH . "/libraries/$classname_path.php";
		}
		
		if(file_exists($classname_path)) {
			require_once($classname_path);
		} else {
			throw new Ingenii_Loader_Exception("$classname could not be found in $classname_path");
		}
	}
	
}

class Ingenii_Loader_Exception extends Exception {}